#include "graphvisualview.h"

GraphVisualView::GraphVisualView(QWidget *window, GraphModelsList *list)
{
    mainWindow = window;
    graphList = list;

    layout = new QGridLayout(this);
    next   = new QPushButton("Next", this);
    prev   = new QPushButton("Prev", this);
    close  = new QPushButton("Close", this);
    text   = new QPushButton("Text", this);

    pic = new GraphPic(graphList, this);
    InitSignalSlots();
    DrawWindow();
}

void GraphVisualView::DrawWindow() {

    layout->addWidget(pic, 0, 0, 1, 4);
    layout->addWidget(prev, 1, 0);
    layout->addWidget(close, 1, 1);
    layout->addWidget(text, 1, 2);
    layout->addWidget(next, 1, 3);
    this->show();
}

void GraphVisualView::InitSignalSlots()
{
    QObject::connect(close,  SIGNAL(clicked()), this, SLOT(closeButtonEvent()));
    QObject::connect(next,   SIGNAL(clicked()), this, SLOT(nextButtonEvent()));
    QObject::connect(prev,   SIGNAL(clicked()), this, SLOT(prevButtonEvent()));
    QObject::connect(text,   SIGNAL(clicked()), this, SLOT(textButtonEvent()));
}

void GraphVisualView::closeButtonEvent()
{
    mainWindow->show();
    delete this;
}

void GraphVisualView::nextButtonEvent()
{
    graphList->increaseGraphNum();
    pic->update();
}

void GraphVisualView::prevButtonEvent()
{
    graphList->decreaseGraphNum();
    pic->update();
}

void GraphVisualView::textButtonEvent() {
    GraphTextView *textViewWindow = new GraphTextView(mainWindow, graphList);
    delete this;
}

GraphVisualView::~GraphVisualView() {

}
